package com.bensonbasement.snorflux.memory;

import java.util.List;

import com.bensonbasement.snorflux.utils.Coords;

public class RSpace extends RWorldElement implements IRBigEntityHolder, IRSmallEntityHolder {
	
	private SpaceInfo info;
	private final RLevel level;
	private RBigEntity bigEntity;
	
	private RInventoryHelper inventoryHelper;
	
	public RSpace(RWorld world, SpaceInfo info, RLevel level) {
		super(world);
		this.inventoryHelper = new RInventoryHelper();
		this.level = level;
		setInfo(info);
	}
	
	public void setInfo(SpaceInfo info) {
		this.info = info;
	}

	public Coords getCoords() {
		return this.info.getCoords();
	}
	
	public int getLevelNum() {
		return this.info.getLevelNum();
	}

	@Override
	public void setBigEntity(RBigEntity entity) {
		if (entity != null && this.bigEntity != null && entity != this.bigEntity) {
			throw new RuntimeException("Trying to add RBigEntity to already-occupied RSpace!");
		}
		this.bigEntity = entity;
	}

	@Override
	public RBigEntity getBigEntity() {
		return this.bigEntity;
	}

	@Override
	public RLevel getLevel() {
		return this.level;
	}

	@Override
	public RSpace getSpace() {
		return this;
	}

	@Override
	public void addSmallEntity(RSmallEntity entity) {
		inventoryHelper.addSmallEntity(entity);
	}

	@Override
	public void removeSmallEntity(RSmallEntity entity) {
		inventoryHelper.removeSmallEntity(entity);
	}

	@Override
	public List<RSmallEntity> getSmallEntities() {
		return inventoryHelper.getSmallEntities();
	}

	@Override
	protected SpaceInfo getInfo() {
		return this.info;
	}
	
}
